# -*- coding: utf-8 -*-
# =============================================================================
#     FileName:
#         Desc:
#       Author:
#        Email:
#     HomePage:
#      Version:
#   LastChange:
#      History:
# =============================================================================

from utils.logger_helper import LoggerHelper

logger = LoggerHelper.get_logger()


class TaskItem(object):
    def __init__(self):
        self.task_id = ""
        self.task_name = ""
        self.task_host = ""
        self.task_cmd = ""
        self.task_status = None
        self.create_time = None
        self.update_time = None

    def _format_log_message(self, log_message):
        return "[task-{}]: {}".format(self.task_id, log_message)

    def log_debug(self, log_message):
        logger.debug(self._format_log_message(log_message))

    def log_info(self, log_message):
        logger.info(self._format_log_message(log_message))

    def log_warning(self, log_message):
        logger.warning(self._format_log_message(log_message))

    def log_database(self, log_message):
        logger.info(self._format_log_message(log_message))

    @classmethod
    def get_pending_tasks(cls):
        """
        获取等待执行的任务列表
        :return:
        """
        return []

    @classmethod
    def get_running_tasks(cls):
        """
        获取正在执行的任务列表
        :return:
        """
        return []

    @classmethod
    def get_stopping_tasks(cls):
        """
        获取等待停止的任务列表
        :return:
        """
        return []

    def update_task_status(self, task_status):
        """
        更新任务的状态,并刷新会数据库和记录更新日志
        :param task_status:
        :return:
        """
        pass
